package com.linkhub.oms.admin.modules.logistic.freighttemplate.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.linkhub.oms.admin.common.exception.ExceptionFactory;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.param.LogisticFreightTemplateAddParam;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.param.LogisticFreightTemplateQueryParam;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.param.LogisticFreightTemplateUpdParam;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.vo.FreightTemplateDetailVO;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.vo.LogisticFreightTemplateDetailVO;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.vo.LogisticFreightTemplateExcelVO;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.vo.LogisticFreightTemplateVO;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.excel.dto.FreightTemplateExcelDataDTO;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.excel.listener.FreightTemplateExcelDataListener;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.service.LogisticFreightTemplateBsService;
import com.linkhub.oms.common.enums.logistic.CountryCodeMappingEnum;
import com.linkhub.oms.common.enums.mp.CurrencyTypeEnum;
import com.linkhub.oms.common.enums.mp.DataStatusEnum;
import com.linkhub.oms.common.response.PageDTO;
import com.linkhub.oms.common.util.*;
import com.linkhub.oms.common.util.json.QtFastjsonUtil;
import com.linkhub.oms.component.excel.util.EasyExcelUtil;
import com.linkhub.oms.dao.mpservice.ICountryPartitionService;
import com.linkhub.oms.dao.mpservice.ILogisticFreightTemplateDetailService;
import com.linkhub.oms.dao.mpservice.ILogisticFreightTemplateService;
import com.linkhub.oms.dao.mpservice.ILogisticService;
import com.linkhub.oms.entity.CountryPartitionEntity;
import com.linkhub.oms.entity.LogisticEntity;
import com.linkhub.oms.entity.LogisticFreightTemplateDetailEntity;
import com.linkhub.oms.entity.LogisticFreightTemplateEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 物流运费模板 服务类
 * </p>
 *
 * @author Frank
 */
@Service
@Slf4j
public class LogisticFreightTemplateBsServiceImpl implements LogisticFreightTemplateBsService {
    @Resource
    private ILogisticFreightTemplateService logisticFreightTemplateService;
    @Resource
    private ILogisticFreightTemplateDetailService logisticFreightTemplateDetailService;
    @Resource
    private ICountryPartitionService countryPartitionService;
    @Resource
    private ILogisticService logisticService;

    @Override
    public PageDTO<LogisticFreightTemplateVO> getLogisticFreightTemplatePage(LogisticFreightTemplateQueryParam param) {
        LambdaQueryWrapper<LogisticFreightTemplateEntity> queryWrapper = Wrappers.lambdaQuery(LogisticFreightTemplateEntity.class)
                .eq(StringUtils.isNotBlank(param.getCountryCode()), LogisticFreightTemplateEntity::getCountryCode, param.getCountryCode())
                .like(StringUtils.isNotBlank(param.getTemplateName()), LogisticFreightTemplateEntity::getTemplateName, param.getTemplateName())
                .like(StringUtils.isNotBlank(param.getChannelCName()), LogisticFreightTemplateEntity::getChannelCName, param.getChannelCName())
                .eq(LogisticFreightTemplateEntity::getDataStatus, DataStatusEnum.ENABLE)
                .orderByAsc(LogisticFreightTemplateEntity::getChannelCName)
                .orderByDesc(LogisticFreightTemplateEntity::getCreatedTime);

        Page<LogisticFreightTemplateEntity> objectPage = new Page<>(param.getPage(), param.getSize());
        Page<LogisticFreightTemplateEntity> page = logisticFreightTemplateService.page(objectPage, queryWrapper);
        return logisticFreightTemplateBuilder(page);
    }

    /**
     * 构建LogisticFreightTemplateVO
     */
    private PageDTO<LogisticFreightTemplateVO> logisticFreightTemplateBuilder(Page<LogisticFreightTemplateEntity> page) {
        PageDTO<LogisticFreightTemplateVO> res = new PageDTO<>();
        res.setTotal(page.getTotal());
        res.setSize(page.getSize());
        res.setCurrent(page.getCurrent());
        res.setPages(page.getPages());
        List<LogisticFreightTemplateVO> logisticFreightTemplates = QtStreamUtil.map(page.getRecords(), LogisticFreightTemplateVO::new);
        res.setRecords(logisticFreightTemplates);
        return res;
    }

    @Override
    public LogisticFreightTemplateDetailVO getLogisticFreightTemplateDetail(Long id) {
        LogisticFreightTemplateEntity entity = logisticFreightTemplateService.getById(id);
        if (Objects.isNull(entity)) {
            throw ExceptionFactory.getI18nBizException("freight.template.does.not.exist");
        }
        List<LogisticFreightTemplateDetailEntity> detailEntities = logisticFreightTemplateDetailService.listByFreightTemplateId(entity.getId());
        return new LogisticFreightTemplateDetailVO(entity, detailEntities);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addLogisticFreightTemplate(LogisticFreightTemplateAddParam logisticFreightTemplateAddParam) {
        //校验模板名称
        List<LogisticFreightTemplateEntity> entitiesOfTemplateName =
                logisticFreightTemplateService.listByTemplateNames(Lists.newArrayList(logisticFreightTemplateAddParam.getTemplateName()));
        if (CollUtil.isNotEmpty(entitiesOfTemplateName)) {
            throw ExceptionFactory.getI18nBizException("freight.template.duplicate");
        }
        //校验分区
        String countryCode = logisticFreightTemplateAddParam.getCountryCode();
        List<CountryPartitionEntity> countryPartitionEntities = countryPartitionService.listByCountryCode(countryCode);
        boolean hasCountryPartition = QtStreamUtil.anyMatch(countryPartitionEntities,
                countryPartitionEntity -> StringUtils.isNotBlank(countryPartitionEntity.getCountryPartition()));
        String countryPartition = logisticFreightTemplateAddParam.getCountryPartition();
        if (hasCountryPartition && StringUtils.isBlank(countryPartition)) {
            throw ExceptionFactory.getI18nBizException("freight.template.country.partition.empty");
        }

        //校验生效日期
        List<LogisticFreightTemplateEntity> entitiesOfChannel = logisticFreightTemplateService.listByChanelAndCountry(logisticFreightTemplateAddParam.getChannelCode(),
                countryCode);
        if (hasCountryPartition) {
            //有分区根据分区模板校验
            entitiesOfChannel = QtStreamUtil.filter(entitiesOfChannel, entity -> Objects.equals(countryPartition, entity.getCountryPartition()));
        }
        boolean dateOverlapsFlag = QtStreamUtil.anyMatch(entitiesOfChannel, entity -> LkDateUtil.overlapsWith(logisticFreightTemplateAddParam.getEffectiveDateConvert(),
                logisticFreightTemplateAddParam.getExpirationDateConvert(),
                entity.getEffectiveDate(),
                entity.getExpirationDate()));
        if (dateOverlapsFlag) {
            throw ExceptionFactory.getI18nBizException("freight.template.date.overlap");
        }

        LogisticFreightTemplateEntity entity = buildTemplateEntity(logisticFreightTemplateAddParam);
        logisticFreightTemplateService.save(entity);
        if (CollUtil.isEmpty(logisticFreightTemplateAddParam.getTemplateDetails())) {
            throw ExceptionFactory.getI18nBizException(" freight.template.weight.range.empty");
        }
        List<LogisticFreightTemplateDetailEntity> detailEntityList = buildTemplateEntityDetailList(entity.getId(), logisticFreightTemplateAddParam.getTemplateDetails());
        logisticFreightTemplateDetailService.saveBatch(detailEntityList);
    }

    /**
     * 构建模板
     */
    private LogisticFreightTemplateEntity buildTemplateEntity(LogisticFreightTemplateAddParam addParam) {
        LogisticFreightTemplateEntity entity = new LogisticFreightTemplateEntity();
        QtBeanUtil.copyProperties(addParam, entity);
        entity.setEffectiveDate(addParam.getEffectiveDateConvert());
        entity.setExpirationDate(addParam.getExpirationDateConvert());
        entity.setUpdateUserId(addParam.getUserId());
        entity.setCreatedUserId(addParam.getUserId());
        return entity;
    }

    /**
     * 构建模板详情
     */
    private List<LogisticFreightTemplateDetailEntity> buildTemplateEntityDetailList(Long id, List<FreightTemplateDetailVO> templateDetails) {
        return QtStreamUtil.map(templateDetails,
                templateDetail -> QtBeanUtil.copyProperties(templateDetail, new LogisticFreightTemplateDetailEntity(),
                        (src, tar) -> {
                            tar.setLogisticFreightTemplateId(id);
                        }));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updLogisticFreightTemplate(LogisticFreightTemplateUpdParam logisticFreightTemplateUpdParam) {
        LogisticFreightTemplateEntity entity = logisticFreightTemplateService.getById(logisticFreightTemplateUpdParam.getId());
        if (Objects.isNull(entity)) {
            throw ExceptionFactory.getI18nBizException("freight.template.does.not.exist");
        }
        //校验生效日期
        String countryCode = entity.getCountryCode();
        List<LogisticFreightTemplateEntity> entitiesOfChannel = logisticFreightTemplateService.listByChanelAndCountry(entity.getChannelCode(),
                countryCode);
        entitiesOfChannel = QtStreamUtil.filter(entitiesOfChannel, entityOfChannel -> !Objects.equals(entity.getId(), entityOfChannel.getId()));
        if (StringUtils.isNotBlank(entity.getCountryPartition())) {
            entitiesOfChannel = QtStreamUtil.filter(entitiesOfChannel, entityOfChannel -> Objects.equals(entity.getCountryPartition(), entityOfChannel.getCountryPartition()));
        }
        boolean dateOverlapsFlag = QtStreamUtil.anyMatch(entitiesOfChannel, entityOfChannel -> LkDateUtil.overlapsWith(logisticFreightTemplateUpdParam.getEffectiveDateConvert(),
                logisticFreightTemplateUpdParam.getExpirationDateConvert(),
                entity.getEffectiveDate(),
                entity.getExpirationDate()));
        if (dateOverlapsFlag) {
            throw ExceptionFactory.getI18nBizException("freight.template.date.overlap");
        }
        LogisticFreightTemplateEntity updEntity = new LogisticFreightTemplateEntity();
        QtBeanUtil.copyProperties(logisticFreightTemplateUpdParam, updEntity);
        updEntity.setEffectiveDate(logisticFreightTemplateUpdParam.getEffectiveDateConvert());
        updEntity.setExpirationDate(logisticFreightTemplateUpdParam.getExpirationDateConvert());
        logisticFreightTemplateService.updateById(updEntity);

        //更新
        List<FreightTemplateDetailVO> templateDetails = logisticFreightTemplateUpdParam.getTemplateDetails();
        List<FreightTemplateDetailVO> updTemplateDetails = QtStreamUtil.filter(templateDetails, templateDetail -> Objects.nonNull(templateDetail.getId()));
        List<LogisticFreightTemplateDetailEntity> updTemplateDetailEntities = buildTemplateEntityDetailList(updEntity.getId(), updTemplateDetails);

        //删除未提交的
        List<LogisticFreightTemplateDetailEntity> detailEntityExists = logisticFreightTemplateDetailService.listByFreightTemplateId(logisticFreightTemplateUpdParam.getId());
        List<Long> updIds = QtStreamUtil.map(updTemplateDetailEntities, LogisticFreightTemplateDetailEntity::getId);
        List<LogisticFreightTemplateDetailEntity> detailListDel = QtStreamUtil.filter(detailEntityExists, detailEntity -> !updIds.contains(detailEntity.getId()));
        detailListDel.forEach(detailEntity -> detailEntity.setDataStatus(DataStatusEnum.DELETE));
        updTemplateDetailEntities.addAll(detailListDel);
        QtOptionalUtil.of(updTemplateDetailEntities).ifPresent(value -> logisticFreightTemplateDetailService.updateBatchById(value));

        //新增
        List<FreightTemplateDetailVO> addTemplateDetails = QtStreamUtil.filter(templateDetails, templateDetail -> Objects.isNull(templateDetail.getId()));
        List<LogisticFreightTemplateDetailEntity> addTemplateDetailEntities = buildTemplateEntityDetailList(updEntity.getId(), addTemplateDetails);
        QtOptionalUtil.of(addTemplateDetailEntities).ifPresent(value -> logisticFreightTemplateDetailService.saveBatch(value));

    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delLogisticFreightTemplate(Long id) {
        LogisticFreightTemplateEntity entity = logisticFreightTemplateService.getById(id);
        if (Objects.isNull(entity)) {
            throw ExceptionFactory.getI18nBizException("freight.template.does.not.exist");
        }
        entity.setDataStatus(DataStatusEnum.DELETE);
        logisticFreightTemplateService.updateById(entity);
        List<LogisticFreightTemplateDetailEntity> detailEntities = logisticFreightTemplateDetailService.listByFreightTemplateId(entity.getId());
        if (CollUtil.isEmpty(detailEntities)) {
            return;
        }
        detailEntities.forEach(detailEntity -> detailEntity.setDataStatus(DataStatusEnum.DELETE));
        logisticFreightTemplateDetailService.updateBatchById(detailEntities);
    }

    @Override
    public List<String> getCountryPartition(String countryCode) {
        return QtStreamUtil.filterAndMap(countryPartitionService.listByCountryCode(countryCode),
                countryPartitionEntity -> StringUtils.isNotBlank(countryPartitionEntity.getCountryPartition()),
                CountryPartitionEntity::getCountryPartition);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public LogisticFreightTemplateExcelVO importExcel(MultipartFile file, String userId) {
        FreightTemplateExcelDataListener excelDataListener = new FreightTemplateExcelDataListener();
        List<FreightTemplateExcelDataDTO> list = EasyExcelUtil.read(file, FreightTemplateExcelDataDTO.class, excelDataListener);
        int failTotal = CollUtil.size(excelDataListener.acquireInValidList());
        if (CollUtil.isEmpty(list)) {
            return LogisticFreightTemplateExcelVO.failResult(failTotal);
        }
        //查询渠道
        List<String> channelCodes = QtStreamUtil.mapAndDistinct(list, FreightTemplateExcelDataDTO::getChannelCode);
        List<LogisticEntity> logisticList = logisticService.listByChannelCodes(channelCodes);
        Map<String, LogisticEntity> channelCodeMap = QtStreamUtil.toMap(logisticList, LogisticEntity::getChannelCode);

        //查询分区
        Map<String, List<CountryPartitionEntity>> countryCodeMap =
                countryPartitionService.listByCountryCodes(QtStreamUtil.mapAndDistinct(list, FreightTemplateExcelDataDTO::getCountryCode));

        //根据模板名称查询
        List<LogisticFreightTemplateEntity> entitiesOfTemplateName =
                logisticFreightTemplateService.listByTemplateNames(QtStreamUtil.mapAndDistinct(list, FreightTemplateExcelDataDTO::getTemplateName));
        List<String> templateNamesExists = QtStreamUtil.mapAndDistinct(entitiesOfTemplateName, LogisticFreightTemplateEntity::getTemplateName);

        //根据渠道查询
        List<LogisticFreightTemplateEntity> freightTemplatesOfChannel = logisticFreightTemplateService.listByChanelCodes(channelCodes);


        Map<String, List<FreightTemplateExcelDataDTO>> templateNameMap = QtStreamUtil.group(list, FreightTemplateExcelDataDTO::getTemplateName);
        List<LogisticFreightTemplateDetailEntity> allFreightTemplateDetails = Lists.newArrayList();
        templateNameMap.forEach((templateName, templates) -> {
            LinkedList<FreightTemplateExcelDataDTO> freightTemplateExcelList = Lists.newLinkedList();
            templates.forEach(template -> {
                LogisticEntity logisticEntity = channelCodeMap.get(template.getChannelCode());
                //校验模板
                FreightTemplateExcelDataDTO excelDataDTO = validateData(template, logisticEntity, countryCodeMap,
                        templateNamesExists, freightTemplatesOfChannel);
                if (Objects.nonNull(excelDataDTO)) {
                    freightTemplateExcelList.add(excelDataDTO);
                }
            });

            if (CollUtil.isNotEmpty(freightTemplateExcelList)) {
                LogisticFreightTemplateEntity entity = convertFreightTemplate(freightTemplateExcelList.get(0), userId);
                logisticFreightTemplateService.save(entity);
                allFreightTemplateDetails.addAll(convertFreightTemplateDetailEntity(entity.getId(),
                        freightTemplateExcelList));
            }
        });
        QtOptionalUtil.of(allFreightTemplateDetails).ifPresent(value -> logisticFreightTemplateDetailService.saveBatch(allFreightTemplateDetails));
        int saveSize = CollUtil.size(allFreightTemplateDetails);
        failTotal = failTotal + CollUtil.size(list) - saveSize;
        return LogisticFreightTemplateExcelVO.successResult(failTotal, saveSize);
    }

    /**
     * 校验模板
     *
     * @param excelDataDTO              导入数据
     * @param logisticEntity            渠道
     * @param countryCodeMap            国家分区
     * @param templateNamesExists       已存在的模板名称
     * @param freightTemplatesOfChannel 渠道已配置的模板
     * @return 校验通过的模板
     */
    private FreightTemplateExcelDataDTO validateData(FreightTemplateExcelDataDTO excelDataDTO,
                                                     LogisticEntity logisticEntity,
                                                     Map<String, List<CountryPartitionEntity>> countryCodeMap,
                                                     List<String> templateNamesExists,
                                                     List<LogisticFreightTemplateEntity> freightTemplatesOfChannel) {
        //校验模板名称
        if (templateNamesExists.contains(excelDataDTO.getTemplateName())) {
            log.info("模板名称重复:{}", excelDataDTO.getTemplateName());
            return null;
        }
        if (Objects.isNull(logisticEntity)) {
            log.info("模板名称:{},渠道编码错误：{}", excelDataDTO.getTemplateName(), excelDataDTO.getChannelCode());
            return null;
        }
        CountryCodeMappingEnum countryCodeMappingEnum = CountryCodeMappingEnum.getByCountryCode(excelDataDTO.getCountryCode());
        if (Objects.isNull(countryCodeMappingEnum)) {
            log.info("模板名称:{},渠道编码：{}，国家编码错误：{}", excelDataDTO.getTemplateName(), excelDataDTO.getChannelCode(),
                    excelDataDTO.getCountryCode());
            return null;
        }

        //校验分区
        List<CountryPartitionEntity> countryPartitionEntities = countryCodeMap.get(excelDataDTO.getCountryCode());
        List<CountryPartitionEntity> hasPartitionList = QtStreamUtil.filter(countryPartitionEntities,
                countryPartitionEntity -> StringUtils.isNotBlank(countryPartitionEntity.getCountryPartition()));
        List<LogisticFreightTemplateEntity> existTemplates;
        if (CollUtil.isNotEmpty(hasPartitionList)) {
            CountryPartitionEntity countryPartitionEntity = QtStreamUtil.findFirst(hasPartitionList,
                    hasPartitionEntity -> Objects.equals(hasPartitionEntity.getCountryPartition(), excelDataDTO.getCountryPartition()));
            if (Objects.isNull(countryPartitionEntity)) {
                log.info("模板名称:{},渠道编码：{}，国家编码：{},分区错误:{}", excelDataDTO.getTemplateName(), excelDataDTO.getChannelCode(),
                        excelDataDTO.getCountryCode(), excelDataDTO.getCountryPartition());
                return null;
            }
            existTemplates = QtStreamUtil.filter(freightTemplatesOfChannel, freightTemplateOfChannel ->
                    Objects.equals(freightTemplateOfChannel.getChannelCode(), excelDataDTO.getChannelCode()) &&
                            Objects.equals(freightTemplateOfChannel.getCountryCode(), excelDataDTO.getCountryCode()) &&
                            Objects.equals(freightTemplateOfChannel.getCountryPartition(), excelDataDTO.getCountryPartition()));
        } else {
            //国家无分区传了分区 要置空
            excelDataDTO.setCountryPartition(null);
            existTemplates = QtStreamUtil.filter(freightTemplatesOfChannel, freightTemplateOfChannel ->
                    Objects.equals(freightTemplateOfChannel.getChannelCode(), excelDataDTO.getChannelCode()) &&
                            Objects.equals(freightTemplateOfChannel.getCountryCode(), excelDataDTO.getCountryCode()));
        }
        //校验模板有效期
        boolean dateOverlapsFlag = QtStreamUtil.anyMatch(existTemplates, entity -> LkDateUtil.overlapsWith(excelDataDTO.getEffectiveDate(),
                excelDataDTO.getExpirationDate(),
                entity.getEffectiveDate(),
                entity.getExpirationDate()));
        if (dateOverlapsFlag) {
            log.info("模板名称:{},渠道编码：{}，国家编码：{},分区:{},模板有效期重叠:{}-{}", excelDataDTO.getTemplateName(), excelDataDTO.getChannelCode(),
                    excelDataDTO.getCountryCode(), excelDataDTO.getCountryPartition(),
                    excelDataDTO.getEffectiveDate(),
                    excelDataDTO.getExpirationDate());
            return null;
        }
        excelDataDTO.setLogisticEntity(logisticEntity);
        return excelDataDTO;
    }

    /**
     * convert LogisticFreightTemplateEntity
     */
    private LogisticFreightTemplateEntity convertFreightTemplate(FreightTemplateExcelDataDTO excelDataDTO, String userId) {
        LogisticFreightTemplateEntity entity = new LogisticFreightTemplateEntity();
        entity.setTemplateName(excelDataDTO.getTemplateName());
        entity.setEffectiveDate(excelDataDTO.getEffectiveDate());
        entity.setExpirationDate(excelDataDTO.getExpirationDate());
        LogisticEntity logisticEntity = excelDataDTO.getLogisticEntity();
        entity.setChannelCode(logisticEntity.getChannelCode());
        entity.setChannelCName(logisticEntity.getChannelCName());
        entity.setChannelEName(logisticEntity.getChannelEName());
        entity.setCountryCode(excelDataDTO.getCountryCode());
        entity.setCountryPartition(excelDataDTO.getCountryPartition());
        entity.setBubbleCoefficient(excelDataDTO.getBubbleCoefficient());
        entity.setMinimumChargeableWeight(QtBigDecimalUtil.valueOf(excelDataDTO.getMinimumChargeableWeight()));
        CurrencyTypeEnum currencyTypeEnum = CurrencyTypeEnum.getByType(excelDataDTO.getActualFeeCurrencyType());
        if (Objects.nonNull(currencyTypeEnum)) {
            entity.setActualFeeCurrencyType(currencyTypeEnum.getTypeStr());
        }
        entity.setUpdateUserId(userId);
        entity.setCreatedUserId(userId);
        return entity;
    }

    /**
     * convert LogisticFreightTemplateDetailEntity
     */
    private List<LogisticFreightTemplateDetailEntity> convertFreightTemplateDetailEntity(Long freightTemplateId,
                                                                                         List<FreightTemplateExcelDataDTO> excelDataList) {
        List<LogisticFreightTemplateDetailEntity> detailEntities = Lists.newArrayList();

        excelDataList.forEach(excelDataDTO -> {
            LogisticFreightTemplateDetailEntity detailEntity = new LogisticFreightTemplateDetailEntity();
            detailEntity.setLogisticFreightTemplateId(freightTemplateId);
            detailEntity.setStartingWeight(QtBigDecimalUtil.valueOf(excelDataDTO.getStartingWeight()));
            detailEntity.setEndingWeight(QtBigDecimalUtil.valueOf(excelDataDTO.getEndingWeight()));
            detailEntity.setExternalFreight(QtBigDecimalUtil.valueOf(excelDataDTO.getExternalFreight()));
            detailEntity.setActualFreight(QtBigDecimalUtil.valueOf(excelDataDTO.getActualFreight()));
            detailEntity.setExternalRegistrationFee(QtBigDecimalUtil.valueOf(excelDataDTO.getExternalRegistrationFee()));
            detailEntity.setActualRegistrationFee(QtBigDecimalUtil.valueOf(excelDataDTO.getActualRegistrationFee()));
            detailEntities.add(detailEntity);
        });
        return detailEntities;
    }

}
